home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / LOADGIF.ZIP / ERROR.ASM next >
Assembly Source File  |  1993-08-20  |  5KB  |  127 lines

  1. IDEAL
  2. MODEL SMALL
  3. ;-------------------------------------------------------------------------------
  4. SEGMENT         GIFCODE PARA PUBLIC 'CODE'
  5. ;-------------------------------------------------------------------------------
  6. ASSUME          DS:@DATA, ES:@DATA, CS:GIFCODE, SS:@DATA
  7. ;-------------------------------------------------------------------------------
  8. EVEN
  9. Old24_Offset    dw      0
  10. Old24_Segment   dw      0
  11. CritErrCode     dw      0
  12. PUBLIC          ErrorCode
  13. ErrorCode       dw      0
  14. ;-------------------------------------------------------------------------------
  15. EVEN
  16. PROC            SetIntVector ;al has int vector cx:dx has new vector
  17.                 Push    ds bx
  18.                 Xor     bx, bx
  19.                 Mov     ds, bx
  20.                 Mov     bl, al
  21.                 Shl     bx, 1
  22.                 Shl     bx, 1
  23.                 Mov     [ds:bx], dx
  24.                 Mov     [ds:bx+2], cx
  25.                 Pop     bx ds
  26.                 Ret
  27. ENDP            SetIntVector
  28. ;-------------------------------------------------------------------------------
  29. EVEN
  30. PROC            GetIntVector   ;al has int vector cx:dx has vector
  31.                 Push    ds bx
  32.                 Xor     bx, bx
  33.                 Mov     ds, bx
  34.                 Mov     bl, al
  35.                 Shl     bx, 1
  36.                 Shl     bx, 1
  37.                 Mov     dx, [ds:bx]
  38.                 Mov     cx, [ds:bx+2]
  39.                 Pop     bx ds
  40.                 Ret
  41. ENDP            GetIntVector
  42. ;-------------------------------------------------------------------------------
  43. EVEN
  44. PUBLIC          Hook24
  45. PROC            Hook24
  46.                 Push    ax bx cx dx
  47.                 Mov     al, 024h
  48.                 Call    GetIntVector
  49.                 Mov     [cs:Old24_Offset], dx
  50.                 Mov     [cs:Old24_Segment], cx
  51.                 Mov     al, 024h
  52.                 Mov     dx, offset NewInt24
  53.                 Mov     cx, cs
  54.                 Call    SetIntVector
  55.                 Mov     [cs:CritErrCode], 0
  56.                 Mov     [cs:ErrorCode], 0
  57.                 Pop     dx cx bx ax
  58.                 Ret
  59. ENDP            Hook24
  60. ;-------------------------------------------------------------------------------
  61. ;Uninstalls my critical error handler.
  62. EVEN
  63. PUBLIC          UnHook24
  64. PROC            UnHook24
  65.                 Push    ax bx cx dx
  66.                 Mov     dx, [cs:Old24_Offset]
  67.                 Mov     cx, [cs:Old24_Segment]
  68.                 Mov     al, 024h
  69.                 Call    SetIntVector
  70.                 Pop     dx cx bx ax
  71.                 Ret
  72. ENDP            UnHook24
  73. ;-------------------------------------------------------------------------------
  74. EVEN
  75. PROC            NewInt24
  76.                 Mov     ax, di          ;put error code in ax
  77.                 Xor     ah, ah
  78.                 Mov     [cs:CritErrCode], ax ;store it for later
  79.                 Mov     al, 3           ;tell DOS to ignore the error
  80.                 Iret                    ;return to caller
  81. ENDP            NewInt24
  82. ;-------------------------------------------------------------------------------
  83. ;This sub is called after each disk access to check for errors(either
  84. ;critical or non-critical). If a non-critical error is detected, then DOS's
  85. ;extended error function is also called to determine which type of error
  86. ;occured.
  87. EVEN
  88. PUBLIC          CheckError
  89. PROC            CheckError
  90.                 Pushf                           ;preseve de flags
  91.                 Cmp     [cs:CritErrCode], 0     ;critical error?
  92.                 Jnz     @@CriticalError
  93.                 Popf                            ;get the flags back
  94.                 Jc      @@NormalError           ;normal error?
  95.                 Ret
  96. ;handles normal error
  97. @@NormalError:  Push    ax bx cx dx bp si di ds es  ;preserve the registers
  98.                 Mov     ah, 059h                ;get extended error info.
  99.                 Xor     bx, bx
  100.                 Int     021h
  101.                 Pop     es ds di si bp dx cx bx
  102.                 Add     ax, 100                 ;add 100 to it to descriminate
  103. @@ErrorExit:    Mov     [cs:ErrorCode], ax      ;between critical errors
  104.                 Pop     ax
  105.                 Stc
  106.                 Ret
  107. ;handles critical errors
  108. @@CriticalError:
  109.                 Popf
  110.                 Push    ax
  111.                 Xor     ax, ax                  ;zero out critical error and
  112.                 Xchg    ax, [cs:CritErrCode]    ;get it at the same time
  113.                 Jmp     @@ErrorExit             ;put it in ErrorCode and exit
  114. ENDP            CheckError
  115. ;-------------------------------------------------------------------------------
  116. EVEN
  117. PUBLIC          ErrorReport
  118. PROC            ErrorReport
  119.                 Mov     ax, [cs:ErrorCode]
  120.                 Retf    0
  121. ENDP            ErrorReport
  122. ;-------------------------------------------------------------------------------
  123. ENDS            GIFCODE
  124. ;-------------------------------------------------------------------------------
  125. END
  126.  
  127.